<template>
	<view class="settlement-page">
		<view class="wrap">
			<view class="card" v-for="item in voList" :key="item.id">
				<view class="h">
					<view class="name">{{ item.ticketName }}</view>
					<view class="num">
						<text>{{ item.num }}</text> 张
					</view>
				</view>
				<view class="date">
					预约日期 <text>{{ time }}</text>
				</view>
				<view class="tip" v-if="item.typeName === '学生票'">
					需持全日制大中小学生学生证原件
				</view>
			</view>

			<view class="authentication" v-if="scenicAuth != 0">
				<view class="left">
					<view class="title">预定当前门票需完成账号信息认证</view>

					<view class="field-list" v-if="scenicAuth == '3'">
						<view class="field-item">
							<view class="field-name">手机号</view>
							<image :src="
                  `${img_baseUrl}/statics/std/static/${userInfo.phoneAuth == '1' ? 'cha' : 'dui'}.png`
                "></image>
						</view>
						<view class="field-item">
							<view class="field-name">实名</view>
							<image :src="
                  `${img_baseUrl}/statics/std/static/${userInfo.idcodeAuth == '1' ? 'cha' : 'dui'}.png`
                "></image>
						</view>
						<view class="field-item">
							<view class="field-name">人脸</view>
							<image :src="
                  `${img_baseUrl}/statics/std/static/${userInfo.faceAuth == '1' ? 'cha' : 'dui'}.png`
                "></image>
						</view>
					</view>
					<view class="field-list" v-if="scenicAuth == '2'">
						<view class="field-item">
							<view class="field-name">手机号</view>
							<image :src="
					  `${img_baseUrl}/statics/std/static/${userInfo.phoneAuth == '1' ? 'cha' : 'dui'}.png`
					"></image>
						</view>
						<view class="field-item">
							<view class="field-name">实名</view>
							<image :src="
					  `${img_baseUrl}/statics/std/static/${userInfo.idcodeAuth == '1' ? 'cha' : 'dui'}.png`
					"></image>
						</view>
					</view>
					<view class="field-list" v-if="scenicAuth == '1'">
						<view class="field-item">
							<view class="field-name">手机号</view>
							<image :src="
					  `${img_baseUrl}/statics/std/static/${userInfo.phoneAuth == '1' ? 'cha' : 'dui'}.png`
					"></image>
						</view>
					</view>
				</view>
				<view class="right" v-if="!goAuth" @click="link">
					<view class="auth-btn"> 去认证 </view>
				</view>
			</view>
			<view class="coupon">
				<view class="coupon_sel">
					<text class="lf">优惠券</text>
					<view class="rt" @click="goCoupon()">
						<text v-if="coupon" class="num">-￥{{(coupon.couponAmount / 100).toFixed(2)}}</text>
						<text v-else>请选择使用优惠券</text>
						<image :src="`${img_baseUrl}/statics/std/static/go.png`"></image>
					</view>
				</view>
			</view>
			<view class="coupon">
				<view class="coupon_sel">
					<text class="lf_yk">游客信息</text>
					<view class="rt" @click="show = true">
						<image :src="`${img_baseUrl}/statics/std/static/add.png`"></image>
						<text class="add_yk">添加游客</text>
					</view>
				</view>
				<view class="need_sel">
					<text>需选择 {{ticketInfo.identityCheckType === '3' ? voList[0].num || 1 : 1}} 位游客信息</text>
				</view>
				<view class="boxs">
					<view class="time_box">
						<view class="item" :class="{
                  selected: hasSel.find(val => val.partnerId == item.partnerId),
                }" v-for="(item, index) in canSels" :key="index" @click.stop="selectPersons(item)">
							<view class="today">{{ item.name }}</view>
						</view>
					</view>
				</view>
				<view class="selper_wrap">
					<view class="selper" v-for='(item, index) in hasSel' :key="item.partnerId">
						<view class="sel_index">游客{{ personIndex[index] }}</view>
						<image @click.stop="selectPersons(item)"
							:src="`${img_baseUrl}/statics/std/static/del.png`"></image>
						<view class="con">
							<view class="con_item">
								<text class="item_name">{{item.name}}</text>
								<text class="item_now" v-if='item.isSelf == 1'>当前登陆人</text>
							</view>
							<view class="con_item" v-if="ticketInfo.phoneCheckType !== '1'">
								<view v-if="(ticketInfo.phoneCheckType === '3'&&item.phoneAuth == 0)||(ticketInfo.phoneCheckType !== '3'&&item.phone)">
									<text class="item_lf">联系电话</text>
									<text>{{item.phone}}</text>
								</view>
								<text class="red" @click="editForm(item)" v-if="ticketInfo.phoneCheckType === '2'&&!item.phone">缺少联系电话，点击补充</text>
								<text class="red" @click="editForm(item)" v-if="ticketInfo.phoneCheckType === '3'&&item.phoneAuth !== '0'">联系电话未认证，点击认证</text>
							</view>
							<!-- <view class="con_item" > -->
							<view class="con_item" v-if="ticketInfo.documentCheckType !== '1'">
								<view v-if="(ticketInfo.documentCheckType === '3'&&item.idCodeAuth == 0)||(ticketInfo.documentCheckType !== '3'&&item.idCode)">
									<text class="item_lf">身份证号</text>
									<text>{{item.idCode}}</text>
								</view>
								<text class="red" @click="editForm(item)" v-if="ticketInfo.documentCheckType === '2'&& !item.idCode">缺少身份证号，点击补充</text>
								<text class="red" @click="editForm(item)" v-if="ticketInfo.documentCheckType === '3'&&item.idCodeAuth !== '0'">身份证号未认证，点击补充</text>
							</view>
							<view class="con_item" v-if="ticketInfo.faceCheckType !== '1'">
								<view  v-if="ticketInfo.faceCheckType === '2'&&item.faceAuth == 0">
									<text class="item_lf">人脸识别</text>
									<text>已认证</text>
								</view>
								<text class="red" @click="goTo('/page_my/personalDetails/faceIdentification')" v-if="ticketInfo.documentCheckType === '2'&&item.faceAuth !== '0'">人脸识别未认证，点击认证</text>
							</view>
						</view>
						<view @click="editForm(item)">编辑</view>
					</view>
				</view>
			</view>
		</view>

		<!--  按钮      -->
		<view class="btns">
			<view class="price">
				总价 <text>¥{{ totalPrice }}</text>
			</view>
			<!-- <view class="btn primary w422" :class="{ disable: !goAuth }" @click="confirmReserve">确认预定</view> -->
			<button :loading="isSubmitting" :disabled="isSubmitting" class="btn primary w422"
				:class="{ disable: !goAuth }" @click="confirmReserve">确认预定</button>
		</view>
		<view class="addorEdit" v-if="show">
			<view class="top"></view>
			<view class="popup-content">
				<!-- <view class="add_item_wrap"> -->
				<view class="title">{{ sForm.partnerId?"编辑游客信息":"添加游客信息" }}</view>
				<image class="close" :src="`${img_baseUrl}/statics/std/static/close.png`" mode=""
					@click="closedPop"></image>
				<view class="phone-box">
					<view class="form-item">
						<text class="label">姓名</text>
						<input class="input" name="name" v-model="sForm.name" placeholder="请输入游客姓名,必填" />
					</view>
					<view class="form-item" >
						<text class="label">手机号</text>
						<input class="input" name="phone" v-model="sForm.phone"
							:placeholder="ticketInfo.phoneCheckType!== '1'?'请输入游客手机号，必填':'请输入游客手机号' " />
					</view>
					<view class="form-item" v-if="ticketInfo.phoneCheckType==='3' && sForm.phoneAuth !== '0'">
						<input class="input phone-code" name="phoneAuthCode" v-model="sForm.phoneAuthCode"
							placeholder="验证码" />
						<view class="get-code" @click="sendCode">
							{{ isSending ? countdown + "s" : btnText }}
						</view>
					</view>
					<view class="form-item" v-if="ticketInfo.documentCheckType!=='1'">
						<text class="label">身份证号</text>
						<input class="input" name="idCode" v-model="sForm.idCode"
							:placeholder="ticketInfo.documentCheckType!=='1'?'请输入游客身份证号，必填':'请输入游客身份证号' " />
						<view @click="checkId" v-if="ticketInfo.documentCheckType==='3' && sForm.idCodeAuth !== '0'">身份证号未认证</view>
					</view>
				</view>
				<!-- <view class="close-box" @click="save">{{info.scenicAuth != 0?'认证':'保存'}}</view> -->
				<view class="close-box" @click="save">保存</view>
				<view class="cancel-box" v-if="sForm.partnerId" @click="deletePop()">删除</view>

				<!-- </view> -->
			</view>
		</view>
	</view>
</template>

<script>
	import dayjs from "dayjs";
	import requestPost, {
		requestGet,
		requestPut,
		requestDel,
		login
	} from "@/utils/request";
	import {
		throttle
	} from '@/utils/index.js'
	import WxValidate from "@/utils/WxValidate";
	import validateMobile , {isCardID} from '@/utils/verification.js';
	export default {
		data() {
			return {
				img_baseUrl: process.env.VUE_APP_BASEURL_IMG_API,
				WxValidate: null,
				voList: [],
				ticketDetailVo: {},
				time: "",
				totalPrice: "",
				scenicAuth: '',
				userInfo: {},
				goAuth: false,
				isSubmitting: false,
				ticketPics: [],
				coupon: null,
				personIndex: ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十'],
				canSels: [],
				hasSel: [],
				ticketInfo: null,
				show: false,
				sForm: {
					name: "",
					phone: "",
					idCode: "",
					phoneAuthCode: "",
					//tode身份证验证
					// idCodeAuth: ""
				},
				info: null,
				btnText: '发送验证码',
				countdown: 60,
				timer: null
			};
		},
		props: ["id", "type"],
		beforeDestroy() {
			uni.removeStorageSync('choose-Coupon')
			this.coupon = null
		},
		onShow() {
			console.log('已选优惠券', uni.getStorageSync('choose-Coupon'))
			if (uni.getStorageSync('choose-Coupon')) {
				this.coupon = uni.getStorageSync('choose-Coupon')
			}
			console.log('票务认证', this.$store.state.ticketReserveInfo);
			const {
				voList = [],
					detail = {},
					time = "",
					totalPrice = "0.00",
			} = this.$store.state.ticketReserveInfo;
			this.info = detail
			this.voList = voList;
			this.ticketDetailVo = detail.ticketDetailVo;
			this.ticketPics = detail.ticketPics;
			this.time0 = time;
			this.time = dayjs(time).format("MM月DD日");
			if (this.coupon) {
				if (totalPrice - (this.coupon.couponAmount / 100).toFixed(2) < 0) {
					this.totalPrice = 0.00
				} else {
					this.totalPrice = totalPrice - (this.coupon.couponAmount / 100).toFixed(2)
				}
			} else {
				this.totalPrice = totalPrice;
			}

			this.ticketInfo = voList[0]
			this.initValidate();
			// this.scenicAuth = this.ticketDetailVo?.scenicAuth;

			this.userInfo = Object.prototype.toString.call(uni.getStorageSync('X-UserInfo')) === "[object Object]" ? uni
				.getStorageSync('X-UserInfo') : null;
			const authMap = {
				1: "phoneAuth",
				2: "idcodeAuth",
				3: "faceAuth",
			};
			const authType = this.ticketDetailVo?.scenicAuth;
			console.log('认证信息', this.scenicAuth)
			this.goAuth = this.scenicAuth == 0 ? true : (this.userInfo[authMap[authType]] == 0);
			this.getPersons()
		},
		methods: {
			//删除游客
			deletePop(){
				//编辑
				requestDel(`/baseplatform/partner/${this.sForm.partnerId}`, {
					// _id:
				}).then((res) => {
					uni.hideLoading();
					if (res.code === 200) {
						uni.showToast({
							title: "操作成功！"
						});
						this.reset();
						this.show = false;
						this.getPersons();
					} else {
						uni.showToast({
							title: res.msg || "操作失败！",
							icon: "none"
						});
					}
				});
			},
			//验证身份证号
			checkId() {
				if(isCardID(this.sForm.idCard) != ''){
				  uni.showToast({title: '身份证号码校验未通过！', icon: 'none'});
				  return
				}
				requestPost("/wxUser/checkIdCodeUnique",{idCode: this.sForm.idCard}, '/baseplatform').then(check => {
				  if(check.code === 200){
				    requestPost('/wxAuth/checkIdCard', {name: this.sForm.name, idCard: this.sForm.idCard}, '/baseplatform').then(res => {
				      uni.hideLoading();
				      if(res.code === 200){
				        uni.showToast({title: '认证成功！'});
				        this.getPersons()
				        // uni.navigateBack();
				      }else{
				        uni.showToast({title: res.msg || '操作失败！', icon: 'none'});
				      }
				    })
				  }else{
				    uni.hideLoading();
				    uni.showToast({title: check.msg || '该身份证号已被认证！', icon: 'none'});
				  }
				})
			},
			//发送验证码
			sendMessage(){
			  uni.showLoading({title: '短信发送中'});
			  requestPost("/user/checkPhoneUnique",{phone: this.sForm.phone}, '/system').then(check => {
			    if(check.code === 200){
			      requestGet('/wxAuth/sendMessage', {phone: this.sForm.phone}, '/baseplatform').then(res => {
			        uni.hideLoading();
			        if(res.code == 200){
			          uni.showToast({title: '短信发送成功！', icon: 'none'});
			        }else{
			          uni.showToast({title: res.msg || '短信发送失败！', icon: 'none'});
			        }
			      }).catch(res => console.log('短信发送失败', res))
			    }else{
			      uni.hideLoading();
			      uni.showToast({title: check.msg || '该手机号已被认证', icon: 'none'});
			    }
			  })
			},
			//验证码
			sendCode() {
			  if(!validateMobile(this.sForm.phone)){
			    uni.showToast({title: '请输入正确的手机号码！', icon: 'none'});
			    return
			  }
			  // 发送验证码逻辑
			  this.sendMessage();
			  // 启动倒计时
			  this.isSending = true;
			  const timer = setInterval(() => {
			    this.countdown--;
			    if (this.countdown <= 0) {
			      this.isSending = false;
			      this.btnText = "重新发送";
			      this.countdown = 60;
			      clearInterval(timer); // 清除计时器
			    }
			  }, 1000);
			},
			// 页面跳转
			goTo(url){
					  if (url == '/page_my/personalDetails/faceIdentification') {
						  if (this.userInfo && this.userInfo.idcodeAuth == 0) {
							  uni.navigateTo({
							    url
							  })
						  } else {
							  uni.showToast({title: '请先完成实名认证！', icon: 'none'})
						  }
					  } else {
						  uni.navigateTo({
						    url
						  })
					  }
			},
			//校验表单是否必填
			initValidate() {
				const rules = {
					name: {
						required: true
					},
					phone: {
						required: this.ticketInfo.phoneCheckType !== '1' ? true : false,
						tel: true
					},
					phoneAuthCode: {
						required: this.ticketInfo.phoneCheckType === '3' ? true : false
					},
					idCode: {
						required: this.ticketInfo.documentCheckType !== '1' ? true : false,
						idcard: true
					}
				};
				const message = {
					name: {
						required: "请输入姓名！"
					},
					phone: {
						required: "请输入手机号！",
						tel: "请输入正确的手机号！"
					},
					phoneAuthCode: {
						required: "请输入验证码！"
					},
					idCode: {
						required: "请输入身份证号",
						idcard: "身份证号码校验未通过！",
					},
				};
				this.WxValidate = new WxValidate(rules, message);
			},
			getPersons() {
				requestGet(`/baseplatform/partner/list`).then((res) => {
					if (res.code === 200) {
						console.log('获取了常用游客信息', res)
						this.canSels = res.rows
						if (this.hasSel.length) {
							this.hasSel.map(v => {
								const index = res.rows.findIndex(val => val.partnerId == v.partnerId)
								if (index !== -1) {
									Object.assign(v, res.rows[index])
								}
							})
						}
					}
				});
			},
			addPerson() {

			},
			//保存表单
			save() {
				const isValidate = this.WxValidate.checkForm(this.sForm);
				if (!isValidate) {
					const errorList = this.WxValidate.errorList;
					uni.showToast({
						title: errorList[0].msg,
						icon: "none"
					});
					return false;
				}
				// this.sForm.userId = this.userInfo.userId;
				if (this.ticketInfo.documentCheckType === '3') {
					this.sForm.idCodeAuthRequire = 1
				} else {
					this.sForm.idCodeAuthRequire = 0
				}
				console.log(this.sForm)
				if (this.sForm.partnerId) {
					//编辑
					requestPut('/baseplatform/partner', {
						...this.sForm
					}).then((res) => {
						uni.hideLoading();
						if (res.code === 200) {
							uni.showToast({
								title: "操作成功！"
							});
							this.reset();
							this.show = false;
							this.getPersons();
							const index = this.hasSel.findIndex(val => val.partnerId == item.partnerId)
							this.hasSel.splice(index, 1 )
						} else {
							uni.showToast({
								title: res.msg || "操作失败！",
								icon: "none"
							});
						}
					});
				} else {
					//添加
					requestPost('/baseplatform/partner', {
						...this.sForm
					}).then((res) => {
						uni.hideLoading();
						if (res.code === 200) {
							uni.showToast({
								title: "操作成功！"
							});
							this.reset();
							this.show = false;
							this.getPersons();
						} else {
							uni.showToast({
								title: res.msg || "操作失败！",
								icon: "none"
							});
						}
					});
				}
			},
			//关闭弹窗
			closedPop() {
				this.show = false;
				this.reset()
			},
			//重置表单数据
			reset() {
				this.sForm = {
					name: "",
					phone: "",
					idCode: ""
				}
				this.isSending = false;
				this.codeTxt = "获取验证码";
			},
			//点击编辑按钮
			editForm(item) {
				console.log(item)
				this.show = true;
				this.sForm = {
					...item
				}
			},
			selectPersons(item) {
				if (this.hasSel.findIndex(val => val.partnerId == item.partnerId) == -1) {
					// this.hasSel.push(item)
					if (this.ticketInfo.identityCheckType === '1') {
						if (item.isSelf === '1') {
							if (this.hasSel.findIndex(val => val.partnerId == item.partnerId) == -1) {
								this.hasSel.push(item)
							}
						} else {
							uni.showToast({
								title: "需选择当前登录人！",
								icon: "none"
							});
						}
					} else if (this.ticketInfo.identityCheckType === '2') {
						if (this.hasSel.length < 1) {
							if (this.hasSel.findIndex(val => val.partnerId == item.partnerId) == -1) {
								this.hasSel.push(item)
							}
						} else {
							this.hasSel = [item]
						}
					} else if (this.ticketInfo.identityCheckType === '3') {
						if (this.hasSel.length >= this.ticketInfo.num) {
							uni.showToast({
								title: "您只需添加" + this.ticketInfo.num + "位游客",
								icon: "none"
							});
							// this.hasSel.shift()
							// if (this.hasSel.findIndex(val => val.partnerId == item.partnerId) == -1) {
							// 	this.hasSel.push(item)
							// }
						} else {
							if (this.hasSel.findIndex(val => val.partnerId == item.partnerId) == -1) {
								this.hasSel.push(item)
							}
						}
					}
				} else {
					console.log('进入了这里11')
					this.hasSel = this.hasSel.filter(val => val.partnerId != item.partnerId)
				}
			},
			goCoupon() {
				// const {
				// 	ticketId,
				// 	ticketType
				// } = this.ticketDetailVo;
				// const queryDTO = {
				// 	"id": this.ticketInfo.ticketAttributeId,
				// 	"type": this.ticketInfo.ticketClassify
				// }
				uni.navigateTo({
					url: `/page_my/coupon/list?id=${this.ticketInfo.ticketAttributeId}&type=${this.ticketInfo.ticketClassify}`,
				})
			},
			// 确认下单
			confirmReserve: throttle(function() {
				if (!this.goAuth) {
					uni.showToast({
						icon: 'none',
						title: '请完成认证！'
					})
					return;
				}
				if (this.isSubmitting) return;
				if (this.ticketInfo.identityCheckType === '3') {
					if (this.hasSel.length < this.ticketInfo.num) {
						uni.showToast({
							title: "请选择" + this.ticketInfo.num + "位游客",
							icon: "none"
						});
						return;
					}
				} else {
					if (this.hasSel.length < 1) {
						uni.showToast({
							title: "请选择1位游客",
							icon: "none"
						});
						return;
					}
				}

				if (this.ticketInfo.phoneCheckType === '2') {
					this.hasSel.map((list, index) => {
						if (list.phone == '') {
							uni.showToast({
								title: `请填写游客${index + 1}的手机号码`,
								icon: "none"
							});
						}
					})
				}
				
				if (this.ticketInfo.documentCheckType === '2') {
					this.hasSel.map((list, index) => {
						if (list.idCode == '') {
							uni.showToast({
								title: `请填写游客${index + 1}的身份证号码`,
								icon: "none"
							});
						}
					})
				}
				
				if (this.ticketInfo.phoneCheckType === '3') {
					this.hasSel.map((list, index) => {
						if (list.phoneAuth != 0) {
							uni.showToast({
								title: `请验证游客${index + 1}的手机号码`,
								icon: "none"
							});
						}
					})
				}
				if (this.ticketInfo.documentCheckType === '3') {
					this.hasSel.map((list, index) => {
						if (list.idCodeAuth != 0) {
							uni.showToast({
								title: `请验证游客${index + 1}的身份证号码`,
								icon: "none"
							});
						}
					})
				}
				const partnerIdList = this.hasSel.map((list) => {
					return list.partnerId
				})


				this.isSubmitting = true;
				// const {
				// 	ticketId,
				// 	ticketType
				// } = this.ticketDetailVo;
				// const ticOrderDetailAddDTOList = this.voList.map((item) => {
				// 	return {
				// 		orderTicketType: ticketType,
				// 		ticketId,
				// 		ticConfigId: item.ticConfigId,
				// 		ticketTypeId: item.ticTypeId,
				// 		ticketCount: item.num,
				// 		commonPic: this.ticketPics.length > 0 ? this.ticketPics[0] : '',
				// 		goodPic: this.ticketPics.length > 0 ? this.ticketPics[0] : ''
				// 	};
				// });
				if (this.ticketInfo.ticketClassify == 1) {
					requestPost("/order/scenicTicketBusinessOrder/addScenicTicketOrder", {
						couponId: this.coupon ? this.coupon.id : null,
						orderTcode: this.userInfo.userIdcode,
						orderTname: this.userInfo.nickName,
						orderTotalPrice: this.totalPrice,
						orderTphone: this.userInfo.phonenumber,
						ticOtherId: this.info.ticOtherId,
						partnerIdList: partnerIdList,
						scenicOrderDetailsAddDTO: {
							ticketAttributeId: this.ticketInfo.ticketAttributeId, //门票属性id
							ticOtherId: this.info.ticOtherId,
							ticketCount: this.ticketInfo.num, //数量
							ticketDate: this.time0, //门票日期
							// ticketId:this.ticketInfo.ticketId,//门票id
							ticketMoney: this.ticketInfo.ticketPrice, //金额单价
							ticketName: this.ticketInfo.ticketName, //门票名称
							ticketStockId: this.ticketInfo.ticketStockId, //库存表id
						}
					}).then((res) => {
						if (res.code === 200) {
							// 获取id
							// 判断是否是0元购
							if (this.totalPrice == 0.00) {
								uni.redirectTo({
									url: `/page_index/ticket/result?state=1&id=${res.data}`,
								});
							} else {
								if (this.ticketInfo.ticketClassify == 2) {
									this.getkey(res.msg, this.ticketInfo.ticketClassify);
								}
								if (this.ticketInfo.ticketClassify == 1) {
									this.getPayOrderInfo(res.data, this.ticketInfo.ticketClassify);
								}
							}
							this.isSubmitting = false;
						} else {
							this.isSubmitting = false;
							uni.showToast({
								title: res.msg,
								icon: "none",
							});
						}
					});
				} else {
					requestPost("/order/activityTicketBusinessOrder/addActivityTicketOrder", {
						couponId: this.coupon ? this.coupon.id : null,
						orderTcode: this.userInfo.userIdcode,
						orderTname: this.userInfo.nickName,
						orderTotalPrice: this.totalPrice,
						orderTphone: this.userInfo.phonenumber,
						ticOtherId: this.info.ticOtherId,
						partnerIdList: partnerIdList,
						activityOrderDetailsAddDTO: {
							ticketAttributeId: this.ticketInfo.ticketAttributeId, //门票属性id
							ticOtherId: this.info.ticOtherId,
							ticketCount: this.ticketInfo.num, //数量
							ticketDate: this.time0, //门票日期
							// ticketId:this.ticketInfo.ticketId,//门票id
							ticketMoney: this.ticketInfo.ticketPrice, //金额单价
							ticketName: this.ticketInfo.ticketName, //门票名称
							ticketStockId: this.ticketInfo.ticketStockId, //库存表id
						}
					}).then((res) => {
						if (res.code === 200) {
							// 获取id
							// 判断是否是0元购
							// if (this.totalPrice == 0.00) {
							// 	uni.redirectTo({
							// 		url: `/page_index/ticket/result?state=1&id=${res.data}`,
							// 	});
							// } else {
								if (this.ticketInfo.ticketClassify == 2) {
									this.getkey(res.data.msg, this.ticketInfo.ticketClassify);
								}
							// 	if (this.ticketInfo.ticketClassify == 1) {
							// 		this.getPayOrderInfo(res.data, this.ticketInfo.ticketClassify);
							// 	}
							// }
							this.isSubmitting = false;
						} else {
							this.isSubmitting = false;
							uni.showToast({
								title: res.msg,
								icon: "none",
							});
						}
					});
				}
				// const api =
				// 	this.ticketInfo.ticketClassify == 1 ?
				// 	"/order/scenicTicketBusinessOrder/addScenicTicketOrder" :
				// 	"/order/activityTicketBusinessOrder/addActivityTicketOrder";
				// requestPost(api, {
				// 	couponId: this.coupon ? this.coupon.id : null,
				// 	orderTcode:this.userInfo.userIdcode,
				// 	orderTname:this.userInfo.nickName,
				// 	orderTotalPrice:this.totalPrice,
				// 	orderTphone:this.userInfo.phonenumber,
				// 	ticOtherId: this.info.ticOtherId,
				// 	partnerIdList:partnerIdList ,
				// 	activityOrderDetailsAddDTO: {
				// 		ticketAttributeId: this.ticketInfo.ticketAttributeId,//门票属性id
				// 		ticOtherId: this.info.ticOtherId,
				// 		ticketCount: this.ticketInfo.num ,//数量
				// 	ticketDate:this.time0,//门票日期
				// 	// ticketId:this.ticketInfo.ticketId,//门票id
				// 	ticketMoney:this.ticketInfo.ticketPrice,//金额单价
				// 	ticketName:this.ticketInfo.ticketName,//门票名称
				// 	ticketStockId:this.ticketInfo.ticketStockId,//库存表id
				// 	}
				// }).then((res) => {
				// 	if (res.code === 200) {
				// 		// 获取id
				// 		// 判断是否是0元购
				// 		if (this.totalPrice == 0.00) {
				// 			uni.redirectTo({
				// 				url: `/page_index/ticket/result?state=1&id=${res.data}`,
				// 			});
				// 		} else {
				// 			if (+ticketType === 2) {
				// 				this.getkey(res.msg);
				// 			}
				// 			if (+ticketType === 1) {
				// 				this.getPayOrderInfo(res.data);
				// 			}
				// 		}
				// 		this.isSubmitting = false;
				// 	} else {
				// 		this.isSubmitting = false;
				// 		uni.showToast({
				// 			title: res.msg,
				// 			icon: "none",
				// 		});
				// 	}
				// });
			}, 500),
			// 活动抢票成功后获取订单Id 参数为抢购成功后唯一标识
			getkey(key, type) {
				requestGet(`/order/activityTicketBusinessOrder/orderResult/${key}`).then((res) => {
					if (res.code === 200) {
						if (this.totalPrice == 0.00) {
							uni.redirectTo({
								url: `/page_index/ticket/result?state=1&id=${res.data}`,
							});
						}
						this.getPayOrderInfo(res.data, type);
					} else {
						this.timer = null
						this.timer = setTimeout(() => {
							getkey(key, type)
						}, 300)
					}
				});
			},
			// 支付前获取订单详细
			getPayOrderInfo: function(orderId, type) {
				let api;
				if (type == 1) {
					api = `/pay/pay/transactions/scenic/${orderId}`
				} else if (type == 2) {
					api = `/pay/pay/transactions/activity/${orderId}`
				}
				//活动支付
				requestGet(api).then((res) => {
					if (res.code === 200) {
						//调用微信官方支付接口弹出付款界面,输入密码扣款
						wx.requestPayment({
							provider: "wxpay",
							timeStamp: String(res.data.timeStamp),
							nonceStr: res.data.nonceStr,
							package: res.data.package,
							signType: res.data.signType,
							paySign: res.data.paySign,
							success: function(res) {
								console.log("success:" + JSON.stringify(res));
								uni.redirectTo({
									url: `/page_index/ticket/result?state=1&id=${orderId}&type=${type}`,
								});
							},
							fail: function(err) {
								console.log("fail:" + JSON.stringify(err));
								uni.redirectTo({
									url: `/page_index/ticket/result?state=0&id=${orderId}&type=${type}`,
								});
							},
						});
					} else {
						uni.showToast({
							title: '调起支付失败！',
							icon: 'none'
						})
					}
				});
			},
			link() {
				const authType = this.ticketDetailVo.scenicAuth;
				const routeMap = {
					1: "phone",
					2: "authentication",
					3: "faceIdentification",
				};
				const path = routeMap[authType];
				uni.navigateTo({
					url: `/page_my/personalDetails/${path}`,
				});
			},
		},
	};
</script>

<style lang="scss">
	.popup-content {
		position: relative;
		height: 1384rpx;
		background: #F5F7F6;
		border-radius: 40rpx 40rpx 0 0;
		position: relative;
		box-sizing: border-box;
		padding: 0 40rpx;

		.close {
			position: absolute;
			top: 24rpx;
			right: 24rpx;
			width: 48rpx;
			height: 48rpx;
		}

		.phone-box {
			margin: 44rpx 0 48rpx;
			background: #FFFFFF;
			border-radius: 24rpx;
			box-sizing: border-box;
			padding-left: 24rpx;

			.form-item {
				display: flex;
				align-items: center;
				position: relative;
				margin: 0rpx 0rpx 24rpx;
				height: 96rpx;
				background: #ffffff;
				border-radius: 16rpx 16rpx 16rpx 16rpx;

				.label {
					width: 160rpx;
					font-size: 28rpx;
					font-weight: 400;
					color: rgba(0,0,0,0.5);
					line-height: 40rpx;
				}
				input {
					width: calc(100% - 186rpx);
					height: 96rpx;
					padding: 0 24rpx;
					font-size: 28rpx;
					font-weight: 400;
					color: rgba(0, 0, 0, 0.9);
					line-height: 96rpx;
				}

				.phone-code {
					padding-right: 200rpx;
				}

				.get-code {
					position: absolute;
					right: 24rpx;
					top: 28rpx;
					font-size: 28rpx;
					font-weight: 400;
					color: #3FAA73;
					line-height: 40rpx;
				}
			}
		}

		.title {
			height: 100rpx;
			line-height: 100rpx;
			font-size: 32rpx;
			font-family: Alibaba PuHuiTi 2.0-65 Medium, Alibaba PuHuiTi 20;
			font-weight: 500;
			color: rgba(0, 0, 0, 0.9);
		}

		.close-box,
		.cancel-box {

			border-radius: 44rpx 44rpx 44rpx 44rpx;
			font-size: 32rpx;
			font-family: Alibaba PuHuiTi 2.0-55 Regular, Alibaba PuHuiTi 20;
			font-weight: 400;

			height: 84rpx;
			line-height: 84rpx;
			text-align: center;
		}

		.close-box {
			background: #3FAA73;
			color: #FFFFFF;
			margin-bottom: 24rpx;
		}

		.cancel-box {
			font-weight: 600;
			background: #FFFFFF;
			color: rgba(0, 0, 0, 0.9);
			// border: 2rpx solid rgba(0, 0, 0, 0.1);
		}
	}

	.settlement-page {
		box-sizing: border-box;
		min-height: 100vh;
		background-color: #f7f9fa;

		.wrap {
			padding: 24rpx 32rpx;
		}

		.coupon {
			// height: 104rpx;
			background: #FFFFFF;
			border-radius: 24rpx 24rpx 24rpx 24rpx;
			box-sizing: border-box;
			padding: 32rpx 24rpx;
			margin-top: 24rpx;

			.selper_wrap {
				font-size: 28rpx;
				font-weight: 400;
				color: rgba(0, 0, 0, 0.7);
				line-height: 40rpx;

				.selper {
					box-sizing: border-box;
					padding: 24rpx 0;
					display: flex;
					align-items: center;

					.sel_index {
						width: 104rpx;
					}

					.con {
						width: 420rpx;
						margin-left: 16rpx;

						.con_item {
							margin-bottom: 8rpx;

							text {
								font-size: 28rpx;
								font-weight: 400;
								color: rgba(0, 0, 0, 0.5);
								line-height: 40rpx;
							}

							.red {
								font-size: 28rpx;
								font-weight: 400;
								color: #EA3D3D;
								line-height: 40rpx;
							}

							.item_lf {
								margin-right: 8rpx;
							}

							.item_name {
								font-size: 28rpx;
								font-weight: 600;
								color: rgba(0, 0, 0, 0.8);
								line-height: 40rpx;
								margin-right: 8rpx;
							}

							.item_now {
								font-size: 28rpx;
								font-weight: 600;
								color: #3FAA73;
								line-height: 40rpx;
							}
						}
					}
				}

				image {
					width: 32rpx;
					height: 32rpx;
					display: block;
				}
			}

			.boxs {
				width: 100%;
				height: 112rpx;
				overflow-x: scroll;
				display: flex;
				margin: 24rpx 0;

				&::-webkit-scrollbar {
					display: none;
				}
			}

			.time_box {
				height: 100%;
				display: flex;
				align-items: center;

				.item {
					height: 88rpx;
					background: rgba(243, 246, 245, 1);
					border-radius: 16rpx 16rpx 16rpx 16rpx;
					border: 2rpx solid #B7CABF;
					box-sizing: border-box;
					padding: 24rpx 48rpx;
					margin-right: 16rpx;
					display: flex;
					align-items: center;
					position: relative;

					&::after {
						position: absolute;
						right: -2rpx;
						top: -2rpx;
						color: #fff;
						width: 64rpx;
						height: 40rpx;
						background: rgba(77, 134, 247, 0.102);
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 24rpx;
					}

					&.selected {
						border: 2rpx solid #3FAA73;

						&::after {
							content: "";
							color: #fff;
							width: 40rpx;
							height: 40rpx;
							background: url('../../static/new/sel.png') no-repeat;
							background-size: 100% 100%;
						}
					}

					.today {
						width: 100%;
						height: 100%;
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 28rpx;
						font-weight: 500;
						color: rgba(0, 0, 0, 0.8);
						line-height: 40rpx;
						white-space: nowrap;
					}

					.date {
						margin-top: 4rpx;
						font-size: 28rpx;
						font-weight: 400;
						color: #777f8f;
						line-height: 40rpx;
					}
				}
			}

			.need_sel {
				text {
					font-size: 24rpx;
					font-weight: 400;
					color: rgba(0, 0, 0, 0.5);
					line-height: 32rpx;
				}
			}

			.coupon_sel {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.lf {
					font-size: 28rpx;
					font-weight: 400;
					color: rgba(0, 0, 0, 0.7);
					line-height: 40rpx;
				}

				.rt {
					display: flex;
					align-items: center;

					.num {
						font-size: 28rpx;
						font-weight: 400;
						color: #FF7614;
						line-height: 40rpx;
					}

					.add_yk {
						font-size: 28rpx;
						font-weight: 400;
						color: rgba(0, 0, 0, 0.8);
						line-height: 40rpx;
					}
				}

				.lf_yk {
					font-size: 32rpx;
					font-weight: 600;
					color: rgba(0, 0, 0, 0.8);
					line-height: 44rpx;
				}

				text {
					font-size: 28rpx;
					font-weight: 400;
					color: rgba(0, 0, 0, 0.5);
					line-height: 40rpx;
				}

				image {
					width: 32rpx;
					height: 32rpx;
					display: block;
					margin-left: 8rpx;
				}
			}
		}

		.card {
			background: #ffffff;
			border-radius: 24rpx 24rpx 24rpx 24rpx;
			padding: 24rpx;
			margin-bottom: 24rpx;

			.h {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.name {
					font-size: 32rpx;
					font-weight: 500;
					color: rgba(0, 0, 0, 0.8);
					line-height: 44rpx;
				}

				.num {
					display: flex;
					align-items: center;
					font-size: 32rpx;
					font-weight: 400;
					color: rgba(0, 0, 0, 0.5);
					line-height: 44rpx;

					text {
						font-weight: 500;
						color: rgba(0, 0, 0, 0.8);
						margin-right: 16rpx;
					}
				}
			}

			.date {
				margin-top: 24rpx;
				display: flex;
				align-items: center;
				font-size: 28rpx;
				font-weight: 400;
				color: rgba(0, 0, 0, 0.7);
				line-height: 40rpx;

				text {
					margin-left: 16rpx;
				}
			}

			.tip {
				font-size: 28rpx;
				font-weight: 400;
				color: rgba(0, 0, 0, 0.7);
				line-height: 40rpx;
			}
		}

		.authentication {
			display: flex;
			align-items: center;
			background: rgba(63, 170, 115, 0.10);
			border-radius: 24rpx 24rpx 24rpx 24rpx;
			border: 2rpx solid #3FAA73;
			box-sizing: border-box;
			padding: 24rpx;

			.left {
				flex: 1;

				.title {
					font-size: 28rpx;
					font-weight: 400;
					color: rgba(0, 0, 0, 0.7);
					line-height: 40rpx;
				}

				.field-list {
					display: flex;
					align-items: center;
					margin-top: 16rpx;

					.field-item {
						margin-right: 24rpx;
						display: flex;
						align-items: center;
						font-size: 28rpx;
						font-weight: 700;
						color: rgba(0, 0, 0, 0.8);
						line-height: 40rpx;

						image {
							display: block;
							width: 32rpx;
							height: 32rpx;
							margin-left: 6rpx;
						}
					}
				}
			}

			.right {
				margin-left: 24rpx;
				width: 132rpx;
				height: 64rpx;
				background: #ffffff;
				box-shadow: 0rpx 2rpx 8rpx 0rpx rgba(0, 0, 0, 0.1);
				border-radius: 32rpx 32rpx 32rpx 32rpx;
				opacity: 1;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 28rpx;
				font-weight: 400;
				color: #3FAA73;
				line-height: 32rpx;
			}
		}

		.addorEdit {
			position: fixed;
			top: 0;
			right: 0;
			bottom: 0;
			left: 0;
			background: rgba(0, 0, 0, .3);
			z-index: 99;
			display: flex;
			flex-direction: column;

			.top {
				flex: 1;
			}

			.add_con {
				height: 1200rpx;
				background: #fff;
				border-radius: 40rpx 40rpx 0 0;

				// display: flex;
				// flex-direction: column;
				// align-items: center;
				// padding: 0 40rpx;
				.add_item {
					width: 100%;
					height: 96rpx;
					display: flex;
					align-items: center;
					box-sizing: border-box;
					border-bottom: 2rpx solid rgba(0, 0, 0, 0.1);

					text {
						width: 160rpx;
						font-size: 28rpx;
						font-weight: 400;
						color: #777F8F;
						line-height: 40rpx;
						text-align: left;
					}

					input {
						flex: 1;

						&::placeholder {
							font-size: 28rpx;
							font-weight: 600;
							color: rgba(0, 0, 0, 0.3);
							line-height: 40rpx;
						}
					}
				}

				.btn_cancel {
					height: 84rpx;
					background: #ECEFF1;
					border-radius: 44rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					margin-top: 24rpx;
					font-size: 32rpx;
					font-weight: 400;
					color: rgba(0, 0, 0, 0.7);
					line-height: 32rpx;
				}

				.btn_save {
					height: 84rpx;
					background: #2187FF;
					border-radius: 44rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					margin-top: 48rpx;
					font-size: 32rpx;
					font-weight: 400;
					color: #FFFFFF;
					line-height: 32rpx;
				}

				.add_item_wrap {
					box-sizing: border-box;
					padding: 0 40rpx;
				}

				.tit {
					height: 104rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					box-sizing: border-box;
					padding: 0 24rpx 0 40rpx;

					text {
						font-size: 32rpx;
						font-weight: 500;
						color: rgba(0, 0, 0, 0.9);
						line-height: 44rpx;
					}

					image {
						width: 48rpx;
						height: 48rpx;
						display: block;
					}
				}
			}
		}

		.btns {
			position: fixed;
			bottom: 0;
			width: calc(100% - 64rpx);
			padding: 0 32rpx;
			left: 0;
			height: 124rpx;
			background: #ffffff;
			border-top: 2rpx solid rgba(0, 0, 0, 0.1);
			display: flex;
			padding-bottom: constant(safe-area-inset-bottom);
			padding-bottom: env(safe-area-inset-bottom);
			align-items: center;
			justify-content: space-between;
			z-index: 1;

			.price {
				display: flex;
				align-items: center;
				font-size: 28rpx;
				font-weight: 400;
				color: rgba(0, 0, 0, 0.7);
				line-height: 40rpx;

				text {
					margin-left: 16rpx;
					font-size: 40rpx;
					font-family: D-DIN-Bold, D-DIN;
					font-weight: 700;
					color: #ff7614;
					line-height: 44rpx;
				}
			}

			.btn {
				box-sizing: border-box;
				display: flex;
				align-items: center;
				justify-content: center;
				min-width: 212rpx;
				padding: 0 28rpx;
				height: 88rpx;
				border: 0;
				font-size: 28rpx;
				font-family: Alibaba PuHuiTi 2-55 Regular, Alibaba PuHuiTi 20;
				font-weight: 400;
				border-radius: 100px;
				width: 280rpx;

				&.primary {
					background: #3FAA73;
					// border: 2rpx solid #2187ff;
					color: #fff;
					margin: 0;
				}

				&.disable {
					opacity: 0.7;
				}
			}
		}
	}
</style>